# Contributor: Hani Shawa <hani.shawa@ev-box.com>
# Maintainer: Hani Shawa <hani.shawa@ev-box.com>
pkgname=luacov-html
_rockname=${pkgname#lua-}
pkgver=1.0.0
pkgrel=1
pkgdesc="reporter for LuaCov that generates HTML files to visualize the code coverage"
options="!check" # Test dependencies not available
url="https://github.com/wesen1/luacov-html"
license="MIT"
arch="noarch"
depends="luacov"
makedepends="luarocks"
source="$_rockname-$pkgver.tar.gz::https://github.com/wesen1/luacov-html/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_rockname-$pkgver"
_luaversions="5.1 5.2 5.3"

for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		luarocks-$lver \
			CC="$CC" \
			CFLAGS="$CFLAGS -fPIC" \
			LUA_INCDIR="$(pkg-config --variable=includedir lua$lver)" \
			LUA_LIBDIR="$(pkg-config --variable=libdir lua$lver)" \
			make --tree=./build \
			"$_rockname-$pkgver-"*".rockspec"
			rm "./build/lib/luarocks/rocks-$lver/manifest"
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"

	local path; for path in "lib/luarocks/rocks-$lver" "share/lua/$lver"; do
		mkdir -p "$subpkgdir/usr/${path%/*}"
		mv "$builddir/build/$path" "$subpkgdir/usr/$path/"
	done
}

sha512sums="
68d108a01ba8a8d37fa6297b1663f0c04eac7d5e3161662351a0ae5a201145de4d385f9866be92cd28525b1357c832d7a6d6069ecde039d3d6e0e7b77c973d54  luacov-html-1.0.0.tar.gz
"
